package com.habdqn.jspdemo.im.service.impl;

import com.habdqn.jspdemo.im.dao.CompanyDao;
import com.habdqn.jspdemo.im.dao.impl.CompanyDaoImpl;
import com.habdqn.jspdemo.im.enetity.Company;
import com.habdqn.jspdemo.im.service.CompanyService;

import java.util.Date;
import java.util.List;

/**
 * 公司相关业务方法实现类
 * @author
 */
public class CompanyServiceImpl implements CompanyService {
    private CompanyDao companyDao = new CompanyDaoImpl();

    @Override
    public List<Company> findPage(int pageNo, int pageSize, String likeName) {
        int offset = (pageNo-1)*pageSize;
        if(likeName!=null&&!"".equals(likeName)){
            return companyDao.findPageByLikeName(offset,pageSize,likeName);
        }else {
            return companyDao.findPage(offset,pageSize);
        }
    }

    @Override
    public int getCount(String likeName) {
        if(likeName!=null&&!"".equals(likeName)) {
            return companyDao.getCountByLikeName(likeName);
        }else{
            return companyDao.getCount();
        }
    }

    @Override
    public boolean add(Company company) {
        if(companyDao.save(company)>0){
            return true;
        }
        return false;
    }

    @Override
    public Company getById(int id) {
        return companyDao.getById(id);
    }

    @Override
    public boolean update(Company company) {
        company.setUpdateTime(new Date());
        if(companyDao.update(company)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteById(int id) {
        if(companyDao.deleteById(id)>0){
            return true;
        }
        return false;
    }
}
